<?php
class Vs_City_Mapper
    extends Vs_Mapper
	
{
    public function delete( $city )
    {
		$mapper = Vs_Factory::mapper('Question');
	 	$questions = $mapper->getByParams( array('cityId' => $city->getId()));
		
		if ( count($questions) ){
			throw new Ws_Exception( Ws_Exception::CITY_CANNOT_BE_DELETED );
		}
		
		$mapper = Vs_Factory::mapper('Answer');
	 	$answers = $mapper->getByParams( array('cityId' => $city->getId()));
		
		if ( count($answers) ){
			throw new Ws_Exception( Ws_Exception::CITY_CANNOT_BE_DELETED );
		}
		
		$mapper = Vs_Factory::mapper('User');
	 	$users = $mapper->getByParams( array('cityId' => $city->getId()));
		
		if ( count($users) ){
			throw new Ws_Exception( Ws_Exception::CITY_CANNOT_BE_DELETED );
		}
				
		$table= $this->getTable();
		
		return $table->delete( $city );
	}
}
